<script>
  import { getInfo } from '../config/proxy.js'
  export default {
    data () {
      return {
        full: {
          check: false,
          detail: false,
          edit: false,
          delete: false,
          out: false,
          back: false,
          setUp: false
        },
        branchList: [],
        supplierList: [],
        storeList: [],
        isBranch: false
      }
    },
    methods: {
      openNewWindow (menuId, menuName, perController, uid) { // 新增tab方法
        var _data = {
          menu_id: menuId,
          menu_name: menuName,
          per_controller: perController
        }
        // console.log(this.listData, 'listData')
        this.listData.forEach(element => {
          console.log(menuId.split('_')[0], element.component)
          if (menuId.split('_')[0] === element.component) {
            // console.log(element.selMenu)
            _data.selMenu = element.selMenu
          }
        })
        if (uid) {
          _data.uid = uid
        }
        this.$store.dispatch('addTab', _data)
      }
    },
    computed: {
      listData: function () {
        // console.log(state.updateState.dhmState)
        return this.$store.state.tab.listData
      }
    },
    created () {
      var menuList = JSON.parse(window.sessionStorage.getItem('_menuList'))
      var infoList = JSON.parse(window.sessionStorage.getItem('_userInfo'))
      for (var m of menuList) {
        for (var mm of m.menuArray) {
          if (mm.menu_name === '促销活动管理') {
            for (var my of mm.menuArray) {
              if (my.menu_name === '满减') {
                for (var mp of my.perArray) {
                  if (mp.per_controller === 'check') {
                    this.full.check = true
                  }
                  if (mp.per_controller === 'detail') {
                    this.full.detail = true
                  }
                  if (mp.per_controller === 'back') {
                    this.full.back = true
                  }
                  if (mp.per_controller === 'out') {
                    this.full.out = true
                  }
                  if (mp.per_controller === 'delete') {
                    this.full.delete = true
                  }
                  if (mp.per_controller === 'edit') {
                    this.full.edit = true
                  }
                  if (mp.per_controller === 'setUp') {
                    this.full.setUp = true
                  }
                }
              }
            }
          }
        }
      }
      if (infoList.branchId === 1) {
        this.isBranch = true
        getInfo.branch({}, (res) => {
          console.log(res)
          if (res.message === 'ok') {
            // this.branchList = res.content
            res.content.forEach((item) => {
              if ((item.org_name.indexOf('公司') !== -1 || item.org_name.indexOf('中商惠民') !== -1) &&
              item.org_name.indexOf('智盛科技公司') !== 0 && item.org_name.indexOf('惠民连锁公司') !== 0 &&
              item.org_name.indexOf('惠民彩悦公司') !== 0 && item.org_name.indexOf('香港子公司') !== 0 &&
              item.org_name.indexOf('台湾子公司') !== 0 && item.org_name.indexOf('澳门子公司') !== 0) {
                item.branch_Id = item.org_bid
                item.branch_Name = item.org_name === '中商惠民' ? '总公司' : item.org_name
                this.branchList.push(item)
              }
            })
            console.log(this.branchList, '分公司列表')
          }
        })
      } else {
        this.isBranch = false
      }
      getInfo.supplier({branchId: infoList.branchId}, (res) => {
        if (res.message === 'ok') {
          this.supplierList = res.content.data.list
        }
      }) // 供应商
      getInfo.storeList({branchId: infoList.branchId}, (res) => {
        if (res.message === 'ok') {
          this.storeList = res.content
        }
      }) // 仓库
    }
  }
</script>
